-- set_deltaTime
--
local import = import
---@type behavior_ret
local bret = import('bt/bt_plugin/behavior3/behavior_ret')

local M = {
    name = "set_deltaTime",
    type = "Action",
    desc = "设置下次行为树刷新的间隔时间",
    args = {
        { "val", "int?", "赋值 时间(毫秒)" },
        { "val2", "float?", "乘 数值" },
        { "minTime", "int?", "随机最小时间" },
        { "maxTime", "int?", "随机最大时间" },
    },
}

function M.run(node, env)
    -- node.args.str
    local ctx = env.ctx
    local val = node.args.val
    local val2 = node.args.val2
    local minTime = node.args.minTime
    local maxTime = node.args.maxTime
    if val then
        ctx:setDeltaTime(val)
    end
    if val2 then
        ctx:setDeltaTime(math.floor(ctx.deltaTime * val2))
    end
    if minTime and maxTime then
        math.randomseed(os.time())
        ctx:setDeltaTime(math.random(minTime, maxTime))
    end
    if ctx.deltaTime <= 0 then
        ctx:setDeltaTime(1)
    end
    return bret.SUCCESS
end

return M
